/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.FUNCTION.CUSTOMER;

import BUS.CustomerBUS;
import DTO.CustomerDTO;
import GUI.MAINMENU.Home;
import java.awt.Color;
import java.awt.Image;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author wonka
 */
public class FunctionAddCustomer extends org.jdesktop.swingx.JXPanel {
    /**
     * Creates new form Home
     */
    TableCustomer model_customer=new TableCustomer();
    String sql="select * from customer";
    CustomerBUS customer_bus=new CustomerBUS();
    public FunctionAddCustomer() throws Exception {
        initComponents();
        model_customer.SetTable(jXTable1);
        model_customer.SetData(sql);
                
    }
    public void ReLoadTable(String sql) throws Exception
    {
        this.sql=sql;
        model_customer.RemoveData();
        model_customer.SetData(sql);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        MaKH = new org.jdesktop.swingx.JXTextField();
        HoTen = new org.jdesktop.swingx.JXTextField();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        CMND = new org.jdesktop.swingx.JXTextField();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        DiaChi = new org.jdesktop.swingx.JXTextField();
        jXLabel8 = new org.jdesktop.swingx.JXLabel();
        Email = new org.jdesktop.swingx.JXTextField();
        jXLabel9 = new org.jdesktop.swingx.JXLabel();
        SoDienThoai = new org.jdesktop.swingx.JXTextField();
        jXButton1 = new org.jdesktop.swingx.JXButton();
        btn_Them_Luu = new org.jdesktop.swingx.JXButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();
        btn_CapNhat = new org.jdesktop.swingx.JXButton();
        btn_Xoa = new org.jdesktop.swingx.JXButton();
        btn_NhapLai = new org.jdesktop.swingx.JXButton();

        setBackground(new java.awt.Color(255, 253, 218));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setAutoscrolls(true);
        setScrollableHeightHint(org.jdesktop.swingx.ScrollableSizeHint.FIT);
        setScrollableWidthHint(org.jdesktop.swingx.ScrollableSizeHint.FIT);

        jXLabel2.setBackground(new java.awt.Color(153, 255, 255));
        jXLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Medium_AddCustomer.png"))); // NOI18N
        jXLabel2.setText("Tiếp Nhận Khách Hàng");
        jXLabel2.setFont(new java.awt.Font("Segoe UI Semibold", 1, 18)); // NOI18N

        jXPanel1.setBackground(new java.awt.Color(255, 253, 218));
        jXPanel1.setMinimumSize(new java.awt.Dimension(686, 470));
        jXPanel1.setPreferredSize(new java.awt.Dimension(686, 470));

        jXLabel1.setText("Mã Khách Hàng:");
        jXLabel1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        MaKH.setEnabled(false);

        jXLabel3.setText("Họ và Tên:");
        jXLabel3.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jXLabel5.setText("CMND:");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jXLabel6.setText("Địa chỉ:");
        jXLabel6.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jXLabel8.setText("Email:");
        jXLabel8.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jXLabel9.setText("Điện thoại:");
        jXLabel9.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jXButton1.setBackground(new java.awt.Color(255, 255, 51));
        jXButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        jXButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Close.png"))); // NOI18N
        jXButton1.setText("Thoát");
        jXButton1.setFocusPainted(false);
        jXButton1.setMaximumSize(new java.awt.Dimension(150, 40));
        jXButton1.setMinimumSize(new java.awt.Dimension(150, 40));
        jXButton1.setPreferredSize(new java.awt.Dimension(130, 40));
        jXButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton1ActionPerformed(evt);
            }
        });

        btn_Them_Luu.setBackground(new java.awt.Color(255, 255, 51));
        btn_Them_Luu.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        btn_Them_Luu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Save.png"))); // NOI18N
        btn_Them_Luu.setText("Thêm và Lưu");
        btn_Them_Luu.setFocusPainted(false);
        btn_Them_Luu.setMaximumSize(new java.awt.Dimension(150, 40));
        btn_Them_Luu.setMinimumSize(new java.awt.Dimension(150, 40));
        btn_Them_Luu.setPreferredSize(new java.awt.Dimension(130, 40));
        btn_Them_Luu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Them_LuuActionPerformed(evt);
            }
        });

        jXTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jXTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jXTable1);

        btn_CapNhat.setBackground(new java.awt.Color(255, 255, 51));
        btn_CapNhat.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        btn_CapNhat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Update.png"))); // NOI18N
        btn_CapNhat.setText("Cập Nhật");
        btn_CapNhat.setFocusPainted(false);
        btn_CapNhat.setMaximumSize(new java.awt.Dimension(150, 40));
        btn_CapNhat.setMinimumSize(new java.awt.Dimension(150, 40));
        btn_CapNhat.setPreferredSize(new java.awt.Dimension(130, 40));
        btn_CapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CapNhatActionPerformed(evt);
            }
        });

        btn_Xoa.setBackground(new java.awt.Color(255, 255, 51));
        btn_Xoa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        btn_Xoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/VerySmall_Close.png"))); // NOI18N
        btn_Xoa.setText("Xóa");
        btn_Xoa.setFocusPainted(false);
        btn_Xoa.setMaximumSize(new java.awt.Dimension(150, 40));
        btn_Xoa.setMinimumSize(new java.awt.Dimension(150, 40));
        btn_Xoa.setPreferredSize(new java.awt.Dimension(130, 40));
        btn_Xoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_XoaActionPerformed(evt);
            }
        });

        btn_NhapLai.setBackground(new java.awt.Color(255, 255, 51));
        btn_NhapLai.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        btn_NhapLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Save.png"))); // NOI18N
        btn_NhapLai.setText("Nhập Lại");
        btn_NhapLai.setFocusPainted(false);
        btn_NhapLai.setMaximumSize(new java.awt.Dimension(150, 40));
        btn_NhapLai.setMinimumSize(new java.awt.Dimension(150, 40));
        btn_NhapLai.setPreferredSize(new java.awt.Dimension(130, 40));
        btn_NhapLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_NhapLaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(84, 84, 84)
                .addComponent(btn_NhapLai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52)
                .addComponent(btn_Them_Luu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(btn_CapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55)
                .addComponent(btn_Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 346, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 843, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jXButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(68, 68, 68)
                                .addComponent(CMND, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(50, 50, 50)
                                .addComponent(HoTen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(MaKH, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(69, 69, 69)
                                .addComponent(DiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(78, 78, 78)
                                .addComponent(Email, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)
                                .addComponent(SoDienThoai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(380, 380, 380))))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(MaKH, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jXPanel1Layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(Email, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(HoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CMND, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(253, 253, 253)
                        .addComponent(jXButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(18, 18, 18)))
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_CapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_Them_Luu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_NhapLai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 911, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jXButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton1ActionPerformed
        // TODO add your handling code here:
       Home child = new Home();
        child.setVisible(true);
        child.setSize( this.getSize());
        this.removeAll();
        this.add(child);
        this.validate();
        this.repaint();
    }//GEN-LAST:event_jXButton1ActionPerformed

    private void btn_Them_LuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Them_LuuActionPerformed
        // TODO add your handling code here:
        CustomerBUS bus=new CustomerBUS();
        CustomerDTO info=new CustomerDTO();
        info.setCustomerID(MaKH.getText().trim());
        info.setFullName(HoTen.getText().trim());
        info.setIDNumber(CMND.getText().trim());
        info.setHomeAddress(DiaChi.getText().trim());
        info.setEmail(Email.getText().trim());
        info.setPhone(SoDienThoai.getText().trim());
        if(HoTen.getText().trim().compareTo("")!=0)
        {
            if(CMND.getText().trim().compareTo("")!=0)
            {
                try {
                    //insert
                    if(bus.KiemTraThongTin_KH("{call Check_Customer(?,?,?)}",info.getFullName(), info.getIDNumber())==false)
                    {
                        bus.Insert("{call dbo.Insert_Customer(?,?,?,?,?,?)}",info );
                        JOptionPane.showMessageDialog(null,"them thanh cong");
                        ReLoadTable(sql);
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"khach hang da co tren he thong");
                    }
                    
                    
                    
                    
                } catch (Exception ex) {
                    Logger.getLogger(FunctionAddCustomer.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
            else
            {
                JOptionPane.showMessageDialog(null,"So CMND khong duoc de trong");
            }
        }
        else
        {
            
            if(CMND.getText().trim().compareTo("")!=0)
            {
                //insert
                JOptionPane.showMessageDialog(null,"ho ten khong duoc de trong");
            }
            else
            {
                JOptionPane.showMessageDialog(null,"So CMND khong duoc de trong");
            }
        }
    }//GEN-LAST:event_btn_Them_LuuActionPerformed

    private void btn_CapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CapNhatActionPerformed
        // TODO add your handling code here:
        CustomerDTO info=new CustomerDTO();
        info.setCustomerID(MaKH.getText().trim());
        info.setFullName(HoTen.getText().trim());
        info.setIDNumber(CMND.getText().trim());
        info.setHomeAddress(DiaChi.getText().trim());
        info.setEmail(Email.getText().trim());
        info.setPhone(SoDienThoai.getText().trim());
        try {
            customer_bus.Update("{call dbo.Update_Customer(?,?,?,?,?,?)}", info);
            JOptionPane.showMessageDialog(null, "cap nhat thanh cong");
            ReLoadTable(sql);
        } catch (Exception ex) {
            Logger.getLogger(FunctionAddCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_CapNhatActionPerformed

    private void btn_XoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_XoaActionPerformed
        // TODO add your handling code here:
        CustomerDTO info=new CustomerDTO();
        info.setCustomerID(MaKH.getText().trim());
        info.setFullName(HoTen.getText().trim());
        info.setIDNumber(CMND.getText().trim());
        info.setHomeAddress(DiaChi.getText().trim());
        info.setEmail(Email.getText().trim());
        info.setPhone(SoDienThoai.getText().trim());
        try {
            if(customer_bus.Delete("{call dbo.Delete_Customer(?,?)}", info)==false)
            {
                 JOptionPane.showMessageDialog(null, "Xoa thanh cong");
                 btn_NhapLaiActionPerformed(evt);
                 ReLoadTable(sql);
            }
            else
            {
                 JOptionPane.showMessageDialog(null, "Khong The Xoa Vi Khach hang Dang So Huu So Tiet Kiem???");

            }
           
        } catch (Exception ex) {
            Logger.getLogger(FunctionAddCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_XoaActionPerformed

    private void jXTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable1MouseClicked
        // TODO add your handling code here:
        int index=jXTable1.getSelectedRow();
        for(int i=0;i<jXTable1.getColumnCount();i++)
        {
            if(i==0)
            {
                MaKH.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==1)
            {
                HoTen.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==2)
            {
                CMND.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==3)
            {
                DiaChi.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==4)
            {
                Email.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==5)
            {
                SoDienThoai.setText(jXTable1.getValueAt(index, i)+"");
            }
        }
    }//GEN-LAST:event_jXTable1MouseClicked
    
    private void btn_NhapLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_NhapLaiActionPerformed
        // TODO add your handling code here:
        MaKH.setText("");
        HoTen.setText("");
        CMND.setText("");
        DiaChi.setText("");
        Email.setText("");
        SoDienThoai.setText("");
        
    }//GEN-LAST:event_btn_NhapLaiActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXTextField CMND;
    private org.jdesktop.swingx.JXTextField DiaChi;
    private org.jdesktop.swingx.JXTextField Email;
    private org.jdesktop.swingx.JXTextField HoTen;
    private org.jdesktop.swingx.JXTextField MaKH;
    private org.jdesktop.swingx.JXTextField SoDienThoai;
    private org.jdesktop.swingx.JXButton btn_CapNhat;
    private org.jdesktop.swingx.JXButton btn_NhapLai;
    private org.jdesktop.swingx.JXButton btn_Them_Luu;
    private org.jdesktop.swingx.JXButton btn_Xoa;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXButton jXButton1;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel8;
    private org.jdesktop.swingx.JXLabel jXLabel9;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTable jXTable1;
    // End of variables declaration//GEN-END:variables
}
